import { fileURLToPath, URL } from 'node:url';

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

import { createHtmlPlugin } from 'vite-plugin-html';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';

// https://vitejs.dev/config/
export default defineConfig(() => {
    return {
        plugins: [
            vue(),
            createHtmlPlugin({
                entry: '/src/project/proB/main.ts'
            }),
            AutoImport({
                imports: [
                    'vue',
                    {
                        '@proB/API': [['default', 'request']]
                    }
                ],
                eslintrc: {
                    enabled: false, // Default `false`,需要更新文件的时候把他打开，更新完之后再关闭，否则每次都要生成文件会有问题
                    filepath: 'src/project/proB/.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
                    globalsPropValue: true // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
                },
                dts: 'src/project/proB/auto-imports.d.ts'
            }),
            Components({
                dts: 'src/project/proB/components.d.ts',
                dirs: ['src/project/proB/views'],
                directoryAsNamespace: true //允许子目录作为组件的命名空间前缀。
            })
        ],
        resolve: {
            alias: {
                '@proB': fileURLToPath(new URL('./', import.meta.url)),
                '@': `${process.cwd()}/src`
            }
        },
        build: {
            outDir: 'src/project/proB/dist',
            rollupOptions: {
                input: 'src/project/proB/main.ts'
            }
        }
    };
});
